<?php 

declare(strict_types=1);

namespace WanZ\App\User\Contracts;

use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;

/**
 * Class UserRequestType
 * @package WanZ\App\User\Contracts
 * 
 * @Constants
 */
class UserRequestType extends AbstractConstants
{
    private const CLIENT_USER_TYPE      = 1;     //终端用户类型
    private const OPERATOR_USER_TYPE    = 2;     //运营商类型
    private const SHARE_USER_TYPE       = 3;     //合伙人类型
    private const TEST_USER_TYPE        = 4;     //测试人员类型
    private const MAINTENANCE_USER_TYPE = 5;     //维护人员类型
    private const MAINTAINER            = 6;     //维修人员类型
    private const EXTENSION_7           = 7;     //扩展类型
    private const EXTENSION_8           = 8;     //扩展类型
    private const EXTENSION_9           = 9;     //扩展类型
    private const ADMIN_USER_TYPE       = 10;    //管理人员类型

    /**
     * 获取请求用户类型
     *
     * @return string
     * @throws CommonException
     */
    public function getRequestUserType(int $userRequestType = 0)
    {
        $type = [
            self::CLIENT_USER_TYPE       => 'user',
            self::OPERATOR_USER_TYPE     => 'operator',
            self::SHARE_USER_TYPE        => 'share',
            self::TEST_USER_TYPE         => 'test_user',
            self::MAINTENANCE_USER_TYPE  => 'maintenance',
            self::ADMIN_USER_TYPE        => 'admin'
        ];

        if (in_array($userRequestType, $this->getExtensionFields())) {
            throw new CommonException(ErrorCode::INVALID_PARAMS, '该用户类型暂未使用，请核实');
        }

        if ($userRequestType > 0) {
            return $type[$userRequestType];
        }

        return $type;
    }

    /**
     * 获取扩展字段
     *
     * @return int[]
     */
    private function getExtensionFields(): array
    {
        return [
            self::EXTENSION_7,
            self::EXTENSION_8,
            self::EXTENSION_9
        ];
    }

    /**
     * 获取终端用户类型
     *
     * @return int
     */
    public function getClientUserType(): int
    {
        return self::CLIENT_USER_TYPE;
    }

    /**
     * 获取运营商用户类型
     *
     * @return int
     */
    public function getOperatorUserType(): int
    {
        return self::OPERATOR_USER_TYPE;
    }

    /**
     * 获取合伙人用户类型
     *
     * @return int
     */
    public function getShareUserType(): int
    {
        return self::SHARE_USER_TYPE;
    }

    /**
     * 获取测试人员用户类型
     *
     * @return int
     */
    public function getTestUserType(): int
    {
        return self::TEST_USER_TYPE;
    }

    /**
     * 获取维修人员类型
     *
     * @return int
     */
    public function getMaintainer(): int
    {
        return  self::MAINTAINER;
    }

    /**
     * 获取维护人员用户类型
     *
     * @return int
     */
    public function getMaintenanceUserType(): int
    {
        return self::MAINTENANCE_USER_TYPE;
    }

    /**
     * 获取管理员用户类型
     *
     * @return int
     */
    public function getAdminUserType(): int
    {
        return self::ADMIN_USER_TYPE;
    }
}
